/**
 * Created by jianyijun on 2020/03/20.
 * 应用程序入口，装载路由，redux
 */
import React from 'react';
import { View, StyleSheet, BackHandler } from 'react-native';
import { Provider } from 'react-redux';
import PropTypes from 'prop-types';
import Roots from './Roots';
import store from './state/store';
import Loading from './utils/Loading';
import { Actions } from 'react-native-router-flux'

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  static propTypes = {
    title: PropTypes.string,
  };

  componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
  }

  componentWillUnmount() {
    BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
  }
  handleBackPress = () => {
    console.log(Actions.currentScene);
    if (Actions.currentScene === '_homePage' || Actions.currentScene === 'Accountlogin') {
      BackHandler.exitApp();  // or anything you want
      return false;
    }
    Actions.pop();
    return true;
  }

  render() {
    return (
      <Provider store={store}>
        <View style={styles.container}>
          <Roots />
          {/* <Loading /> */}
        </View>
      </Provider>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});
